package com.binance.notification.web.utils;

import com.google.common.util.concurrent.RateLimiter;

import java.util.concurrent.TimeUnit;

/**
 * 时间窗内限速
 *
 * @author louis
 * @date 2018-04-18 20:05:04
 */
public final class SpeedLimiter {

    private SpeedLimiter() {}

    public static RateLimiter newLimiter(int seconds, int permit) {
        RateLimiter limiter = RateLimiter.create(new Double(permit).doubleValue() / new Double(seconds).doubleValue(),
                1000, TimeUnit.MILLISECONDS);
        return limiter;
    }

}
